import { login } from "../api/user"
import { setToken, removeToken } from '../composables/auth'
export default {

    namespaced: true,
    actions: {
        //登录 储存token
        login({ commit }, { username, password }) {
            return new Promise((resolve, reject) => {
                login(username, password).then(res => {             
                    resolve(res)
                    setToken(res.data.access_token)
                }).catch(err => {
                    reject(err)              
                })
            })
        },      
        //退出登录
        logout({ commit }) {
            //移除cookie里面的token
            removeToken()
        }
    },
    //准备mutations-用于操作数据（state）
    mutations: {
        SET_USERINFO(state, user) {
            state.user = user
        },
        handleAsideWidth(state){
            state.asideWidth=state.asideWidth == "250px" ? "64px" :"250px"
         },
    },
    state: {
        asideWidth:"250px",
        user: {},    
    },
    //准备getters-用于将state中的数据进行加工
    getters: {
        
    }
}